﻿using Guoc.BigMall.Domain.Entity;
using Guoc.BigMall.Infrastructure.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Guoc.BigMall.WebService.Dto
{
    /// <summary>
    ///  用户上下文
    /// </summary>
    public class UserContext
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="customer">客户</param>
        /// <param name="storeCode">当前门店代码</param>
        /// <param name="expire">过期时间，默认30分钟过期</param>
        public UserContext(Member customer)
        {
  
            this.MemberId = customer.Id;         
            this.HeadImage = customer.HeadImage;
            this.NickName = string.IsNullOrEmpty(customer.RealName) ? customer.NickName : customer.RealName;
        }

        public string OpenId { get;  set; }
        public string StoreCode { get; set; }
        public int MemberId { get; private set; }

        public string NickName { get; private set; }

        public string HeadImage { get; set; }

        public string Token { get;  set; }  

        
        /// <summary>
        /// 用户缓存key
        /// </summary>
        public static string GetCacheKey(int memberId)
        {
            return string.Format("member@{0}", memberId);
        }
        /// <summary>
        /// 用户缓存key
        /// </summary>
        public static string GetCacheKey(string memberId)
        {
            return string.Format("member@{0}", memberId);
        }

    }
}
